package com.xmuexp109.exp5.model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
/**
 * 订单视图对象，用于新增
 **/
@Data
@ApiModel(description = "订单视图对象")
public class ordersVo {
    @NotBlank(message="收货人不能为空")
    @ApiModelProperty(value = "收货人")
    private String consignee;

    @ApiModelProperty(value = "地区Id")
    private Long regionId;

    @NotBlank(message="收货地址不能为空")
    @ApiModelProperty(value = "收货地址")
    private String address;

    @NotBlank(message="联系电话不能为空")
    @ApiModelProperty(value ="联系电话")
    private String mobile;

    @ApiModelProperty(value = "附言")
    private String message;

    @ApiModelProperty(value = "使用的优惠卷id")
    private Long couponId;

    @ApiModelProperty(value = "预售活动id")
    private Long presaleId;

    @ApiModelProperty(value = "团购活动id")
    private Long grouponId;

    @ApiModelProperty(value = "订单明细")
    private List<orderItemVo> orderItemVoList;


    /**
     * 由Vo对象创建orders对象
     * @return orders对象
     */
    public orders createOrders(){
        orders orders = new orders();
        orders.setConsignee(this.consignee);
        orders.setRegionId(this.regionId);
        orders.setAddress(this.address);
        orders.setMobile(this.mobile);
        orders.setMessage(this.message);
        orders.setCouponId(this.couponId);
        orders.setPresaleId(this.presaleId);
        orders.setGroupOnId(this.grouponId);
        if (null != this.orderItemVoList) {
            List<orderItem> newOrderItemList = new ArrayList<>(this.orderItemVoList.size());
            for (orderItemVo orderItemVo : this.orderItemVoList) {
                orderItem orderItem1 = orderItemVo.createOrderItem();
                newOrderItemList.add(orderItem1);
            }
            orders.setOrderItemList(newOrderItemList);
        }
        return orders;
    }
}
